export function getPushMessages() {
	return plus.push.getAllMessage();
};

export function changeBadge(number) {
	var messages = getPushMessages();
	plus.runtime.setBadgeNumber(number || messages.length);
};

export function createPushMessages(content, payload = {}, options, changeBadge) {
	plus.push.createMessage(...arguments);
	if (changeBadge) {
		var delay = options.delay ? (~~options.delay * 1000) : 0;
		setTimeout(() => {
			changeBadge();
		}, delay)
	}
};

export function removePushMessage(message, changeBadge) {
	message ? plus.push.remove(message) : plus.push.clear();
	if (changeBadge) {
		changeBadge();
	}
};

export function init() {
	plus.push.addEventListener("click", (message) => {
		let url = message.payload;
		if (url) {
			uni.navigateTo({
				url,
				success: () => {},
				complete: () => {
					removePushMessage(message);
				}
			});
		}
	})
};